#include "mydialog.h"
#include "mainwindow.h"

#include <QPushButton>
#include <QVBoxLayout>

MyDialog::MyDialog(MainWindow *mainWin, QWidget *parent)
        : QDialog(parent), mainWindow(mainWin)
{
    setWindowTitle("MyDialog");

    callMainWinBtn = new QPushButton("调用主窗口函数", this);

    QVBoxLayout *layout = new QVBoxLayout(this);
    layout->addWidget(callMainWinBtn);

    // 点击按钮时调用主窗口函数
    connect(callMainWinBtn, &QPushButton::clicked, this, [this]() {
        if (mainWindow) {
            mainWindow->doSomething();
        }
    });
}
